package com.sudo.controller;

import com.sudo.aspect.AuthorizationApi;
import com.sudo.common.utils.JsonRes;
import com.sudo.common.utils.PagedGridResult;
import com.sudo.service.SysUserBehaviorService;
import com.sudo.service.SysUserLoginRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author：为道日损 2020-06-19 16:39
 * webSite：https://www.sudo.ren
 */
@Api(value = "用户记录",tags = {"用户行为记录的接口"})
@RestController
@RequestMapping("userBehavior")
public class SysLogController extends BaseController {

    @Autowired
    private SysUserBehaviorService sysUserBehaviorService;

    @Autowired
    private SysUserLoginRecordService sysUserLoginRecordService;

    @AuthorizationApi(menu = "user_behavior",button = "search")
    @ApiOperation(value = "分页查询用户行为记录",notes = "分页查询用户行为记录",httpMethod = "GET")
    @GetMapping("/queryUserBehaviorByPage")
    public JsonRes queryUserBehaviorByPage(@RequestParam Integer page,
                                           @RequestParam Integer pageSize,
                                           @RequestParam String username ,
                                           @RequestParam String startDate,
                                           @RequestParam String endDate) {
        PagedGridResult pagedGridResult = sysUserBehaviorService.queryUserBehaviorByPage(page, pageSize, username,startDate,endDate);
        return JsonRes.ok(pagedGridResult);
    }

    @ApiOperation(value = "分页查询我的行为记录",notes = "分页查询我的行为记录",httpMethod = "GET")
    @GetMapping("/queryMyBehaviorByPage")
    public JsonRes queryMyBehaviorByPage(@RequestParam Integer page,
                                         @RequestParam Integer pageSize,
                                         HttpServletRequest request) {
        String sessionUser = getSessionUser(request);
        PagedGridResult pagedGridResult = sysUserBehaviorService.queryUserBehaviorByPage(page, pageSize, sessionUser,null,null);
        return JsonRes.ok(pagedGridResult);
    }

    @AuthorizationApi(menu = "user_loginRecord",button = "search")
    @ApiOperation(value = "分页查询用户登录记录",notes = "分页查询用户登录记录",httpMethod = "GET")
    @GetMapping("/queryUserLoginRecordByPage")
    public JsonRes queryUserLoginRecordByPage(@RequestParam Integer page,
                                           @RequestParam Integer pageSize,
                                           @RequestParam String username ,
                                           @RequestParam String startDate,
                                           @RequestParam String endDate) {
        PagedGridResult pagedGridResult = sysUserLoginRecordService.queryUserLoginRecordByPage(page, pageSize, username,startDate,endDate);
        return JsonRes.ok(pagedGridResult);
    }

    @ApiOperation(value = "分页查询我的登录记录",notes = "分页查询我的登录记录",httpMethod = "GET")
    @GetMapping("/queryMyLoginRecordByPage")
    public JsonRes queryMyLoginRecordByPage(@RequestParam Integer page,
                                              @RequestParam Integer pageSize,
                                            HttpServletRequest request) {
        String sessionUser = getSessionUser(request);
        PagedGridResult pagedGridResult = sysUserLoginRecordService.queryUserLoginRecordByPage(page, pageSize, sessionUser,null,null);
        return JsonRes.ok(pagedGridResult);
    }
}
